<?php
require('config.php');

        $user_id=$_REQUEST['user_id'];
        //$user_id=54;
        //$orderId=124;
		$sql="select * from `".$oto."_orders`,`".$oto."_order_goods`,`".$oto."_shops` where ".$oto."_orders.userId='".$user_id."' and `orderFlag`='1' and ".$oto."_orders.orderId=".$oto."_order_goods.orderId and ".$oto."_shops.shopId=".$oto."_orders.shopId and ".$oto."_orders.orderStatus='4'";
		//echo $sql;
		//die();
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$person_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(isset($person_info))
		{
			for($i=0;$i<count($person_info);$i++)
			{
				$goods_id=$person_info[$i]['goodsId'];
				$order_id=$person_info[$i]['orderId'];
				$sql="select * from `".$oto."_goods_appraises` where orderId='{$order_id}' and goodsId='{$goods_id}' and userId='{$user_id}'";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$pingjia_info[$i]=$row;//将取得的所有数据赋值给person_info数组
				}
				if(!isset($pingjia_info[$i]))
				{
					$data1[]=$person_info[$i];
				}
			}

			///////////////////////////////////////////////
			for($i=0;$i<count($person_info);$i++)
			{
				$goods_id=$person_info[$i]['goodsId'];
				$order_id=$person_info[$i]['orderId'];
				$sql="select * from `".$oto."_share` where orderId='{$order_id}' and goodsId='{$goods_id}' and userId='{$user_id}'";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$pingjia_info2[$i][]=$row;//将取得的所有数据赋值给person_info数组
				}
				$sql="select * from `".$oto."_goods_appraises` where orderId='{$order_id}' and goodsId='{$goods_id}' and userId='{$user_id}'";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$appraises_info2[$i][]=$row;//将取得的所有数据赋值给person_info数组
				}
				if(!isset($pingjia_info2[$i]) && isset($appraises_info2[$i]))
				{
					$data2[]=$person_info[$i];
				}
				else
				{
				}
			}
			////////////////////////////////
			$t=0;
			for($i=0;$i<count($person_info);$i++)
			{
				$goods_id=$person_info[$i]['goodsId'];
				$order_id=$person_info[$i]['orderId'];
				$sql="select * from `".$oto."_share` where orderId='{$order_id}' and goodsId='{$goods_id}' and userId='{$user_id}'";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$pingjia_info3[$i][]=$row;//将取得的所有数据赋值给person_info数组
				}
				if(!isset($pingjia_info3[$i]))
				{
					
				}
				else
				{
					$img1=$pingjia_info3[$i][0]['shareImg1'];
					$img2=$pingjia_info3[$i][0]['shareImg2'];
					$img3=$pingjia_info3[$i][0]['shareImg3'];
					$img4=$pingjia_info3[$i][0]['shareImg4'];
					if($img1!="")
					{
						$data3[$t]=$person_info[$i];
						$data3[$t]['isShow']=$pingjia_info3[$i][0]['isShow'];
						$t++;
					}
				}
			}
			/////////////////////////////////
			$t2=0;
			for($i=0;$i<count($person_info);$i++)
			{
				$orderId=$person_info[$i]['orderId'];
		        $goodsId=$person_info[$i]['goodsId'];
		        $shopId=$person_info[$i]['shopId'];
		        $sql="select * from `".$oto."_goods_appraises` where `userId`='".$user_id."' and orderId='{$orderId}' and goodsId='{$goodsId}' and shopId='{$shopId}'";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$appraises_info[$i]=$row;//将取得的所有数据赋值给person_info数组
				}
				if(!isset($appraises_info[$i]))
				{
					$person_info[$i]['pan']=0;
				}
				else
				{
					if($appraises_info[$i]['serviceScore']==0 || $appraises_info[$i]['timeScore']==0 || $appraises_info[$i]['packScore']==0)
					{
						$person_info[$i]['pan']=0;	
						$t2++;
					}
					else
					{
						$person_info[$i]['pan']=1;
					}
				}
			}
			//////////////////////
			if(isset($data1)) $data[0]['num']=count($data1);
			else $data[0]['num']=0;
			if(isset($data2)) $data[1]['num']=count($data2);
			else $data[1]['num']=0;
			if(isset($data3)) $data[2]['num']=count($data3);
			else $data[2]['num']=0;
			$data[3]['num']=$t2;
		}
		else
		{
			$data[0]['num']=0;
			$data[1]['num']=0;
			$data[2]['num']=0;
			$data[3]['num']=0;
		}
		echo json_encode($data);

		//////////////////////////////////////////
?>